package com.ffcs.cn.action.common;

import com.supermap.desktop.controls.ui.controls.colorSelect.SmButtonColorSelector;
import com.supermap.desktop.core.event.colorSelect.IColorChangedListener;
import com.supermap.desktop.core.ui.controls.GridBagConstraintsHelper;
import com.supermap.desktop.core.ui.controls.SMSpinner;
import com.ffcs.cn.DevelopProperties;

import javax.swing.*;
import javax.swing.event.ChangeListener;
import java.awt.*;

/**
 * 面对象风格设置面板
 *
  */
public abstract class StyleSettingPanelRegion extends AbstractStyleSettingPanel {

	/**
	 * 前景色
	 **/
	protected JLabel labelForceColor;
	protected SmButtonColorSelector buttonForceColor;
	/**
	 * 背景色
	 **/
	protected JLabel labelBackgroundColor;
	protected SmButtonColorSelector buttonBackgroundColor;

	/**
	 * 不透明度
	 **/
	protected JLabel labelOpaqueRate;
	protected SMSpinner spinnerOpaque;

	public StyleSettingPanelRegion() {
		initComponents();
		initLayout();
		registerEvents();
	}


	private void initComponents() {
		labelForceColor = new JLabel(DevelopProperties.getString("String_Label_ForceColor"));
		buttonForceColor = new SmButtonColorSelector();
		labelBackgroundColor = new JLabel(DevelopProperties.getString("String_Label_BackColor"));
		buttonBackgroundColor = new SmButtonColorSelector();
		labelOpaqueRate = new JLabel(DevelopProperties.getString("String_Label_OpaqueRate"));
		spinnerOpaque = new SMSpinner();
		spinnerOpaque.setMaxValue(100);
		spinnerOpaque.setMinValue(0);
	}

	private void initLayout() {
		this.setLayout(new GridBagLayout());
		this.setBorder(BorderFactory.createTitledBorder(DevelopProperties.getString("String_StyleSetting")));
		this.add(labelForceColor, new GridBagConstraintsHelper(0, 0, 1, 1)
				.setAnchor(GridBagConstraints.WEST)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP)
				.setFill(GridBagConstraints.NONE)
				.setWeight(0, 0));
		this.add(buttonForceColor, new GridBagConstraintsHelper(1, 0, 2, 1)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP)
				.setAnchor(GridBagConstraints.WEST)
				.setFill(GridBagConstraints.HORIZONTAL)
				.setWeight(1, 0));
		this.add(labelBackgroundColor, new GridBagConstraintsHelper(0, 1, 1, 1)
				.setAnchor(GridBagConstraints.WEST)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP)
				.setFill(GridBagConstraints.NONE)
				.setWeight(0, 0));
		this.add(buttonBackgroundColor, new GridBagConstraintsHelper(1, 1, 2, 1)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP)
				.setAnchor(GridBagConstraints.WEST)
				.setFill(GridBagConstraints.HORIZONTAL)
				.setWeight(1, 0));
		this.add(labelOpaqueRate, new GridBagConstraintsHelper(0, 2, 1, 1)
				.setAnchor(GridBagConstraints.WEST)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP)
				.setFill(GridBagConstraints.NONE)
				.setWeight(0, 0));
		this.add(spinnerOpaque, new GridBagConstraintsHelper(1, 2, 2, 1)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP)
				.setAnchor(GridBagConstraints.WEST)
				.setFill(GridBagConstraints.HORIZONTAL)
				.setWeight(1, 0));
	}

	private void registerEvents() {
		buttonForceColor.addColorChangedListener(getForceColorChangedListener());
		buttonBackgroundColor.addColorChangedListener(getBackgroundColorChangedListener());
		spinnerOpaque.addChangeListener(getOpaqueChangeListener());
	}

	/**
	 * 实现前景色监听的接口
	 *
	 * @return 监听器
	 */
	public abstract IColorChangedListener getForceColorChangedListener();

	/**
	 * 实现背景色监听的接口
	 *
	 * @return 监听器
	 */
	public abstract IColorChangedListener getBackgroundColorChangedListener();

	/**
	 * 实现透明度监听的接口
	 *
	 * @return 监听
	 */
	public abstract ChangeListener getOpaqueChangeListener();

}
